<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./vue.js"></script>
</head>

<body>
    <div id="app">
        <button @click="clickMe">点我</button>
        <!-- 为标签添加ref属性 -->
        <input id="t1" ref="txtName" type="text" name="" id="">
    </div>
    <script>


        let vm = new Vue({
            el: '#app',
            methods: {
                clickMe() {
                    // 在vue中可以通过vue实例.$refs.ref-id名拿到dom对象
                    console.log(vm.$refs.txtName.value)
                    // 验证通过$refs获取的是不是dom对象--------验证结果：确实是dom对象
                    console.log(vm.$refs.txtName instanceof Object)
                    console.log(vm.$refs.txtName instanceof HTMLInputElement)
                    // 遍历$refs获取的dom对象中所有的成员
                    let refsDomNum = 0
                    for (let pro in vm.$refs.txtName) {
                        // console.log(pro);
                        refsDomNum++
                    }

                    // 判断getElement语法获取的dom对象和$refs获取的dom对象属性数量是否一致
                    let dom1 = document.getElementById('t1')
                    let dom1Pro = 0
                    for (let pro in dom1) {
                        dom1Pro++
                    }
                    console.log('refs num=' + refsDomNum);
                    console.log('dom num=' + dom1Pro);

                }
            }
        })
    </script>
</body>

</html>